<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/* CRM In Incoming Call */
class Crm extends Controller {
	
	function Crm(){
		if(!$this->session->userdata('user_id')){
			redirect($this->config->item('auth'));
		}
        if(!$this->session->userdata('menu4')==1){
			redirect($this->config->item('dashboard'));
		}
        $this->load->model('calls');
	}
	
	function index(){
		if($this->session->userdata('user_group')== $this->config->item('admin')):
            $add 		= $this->lang->line('add');
			$add_link 	= $this->config->item('call_add');
			$add_active = $this->config->item('empty');
        else:
            $add 		=""; 
			$add_link 	="";
			$add_active	="";
        endif;      
		
		$data = array(
                        'title'		=>	$this->lang->line('call'),
                        'table'		=>	array(
												'calls'				=>	$this->calls->getAll()
											 ),    
						'content'	=> 	'list',
						'menu' 		=> 	array(
												'dashboard_active'	=>	$this->config->item('empty'),
												'contact_active'	=>	$this->config->item('empty'),
                                                'contactdna_active'	=>	$this->config->item('empty'),
												'activity_active'	=>	$this->config->item('empty'),
												'job_active'		=>	$this->config->item('empty'),
												'call_active'		=>	$this->config->item('active'),
												'user_active'		=>	$this->config->item('empty'),
												'report_active'		=>	$this->config->item('empty'),
												'master_active'		=>	$this->config->item('empty'),
												'graphic_active'	=>	$this->config->item('empty'),
												'setting_active'	=>	$this->config->item('empty'),
											 ),
						'tab'		=>	array(
												'tab1'				=>	$this->lang->line('list'),
												'tab1_link'			=>	$this->config->item('call'),
												'tab1_active'		=>	$this->config->item('active'),
                                                'tab2'				=>	$add,
												'tab2_link'			=>	$add_link,
												'tab2_active'		=>	$add_active,
                                                'tab3'				=>	'',
												'tab4'				=>	'',
												'tab5'				=>	'',
												'tab6'				=>	'',
												'tab7'				=>	'',
												'tab8'				=>	''
											 )					
					 );
		$this->load->vars($data);
		$this->load->theme('default');
	}
    
    function addnew(){
        if($this->session->userdata('user_group')!= $this->config->item('admin') ){
            redirect($this->config->item('call'));
        }
           
		$data = array(
						'title'		=>	$this->lang->line('add'),
						'table'		=>	array(
												'users'				=>	$this->calls->getAllUsers(),
                                                //'pos'				=>	$this->positions->getActive(),
                                                'value'             =>  "",
                                                //'group'				=>	$this->groups->getActive()
											 ),
                        'form'      =>  array('action'=>$this->config->item('call_save')),                     
						'content'	=> 	'form',
						'menu' 		=> 	array(
												'dashboard_active'	=>	$this->config->item('empty'),
												'contact_active'	=>	$this->config->item('empty'),
                                                'contactdna_active'	=>	$this->config->item('empty'),
												'activity_active'	=>	$this->config->item('empty'),
												'job_active'		=>	$this->config->item('empty'),
												'call_active'		=>	$this->config->item('active'),
												'user_active'		=>	$this->config->item('empty'),
												'report_active'		=>	$this->config->item('empty'),
												'master_active'		=>	$this->config->item('empty'),
												'graphic_active'	=>	$this->config->item('empty'),
												'setting_active'	=>	$this->config->item('empty'),
											 ),
						'tab'		=>	array(
												'tab1'				=>	$this->lang->line('list'),
												'tab1_link'			=>	$this->config->item('call'),
												'tab1_active'		=>	$this->config->item('empty'),
												'tab2'				=>	$this->lang->line('add'),
												'tab2_link'			=>	$this->config->item('call_add'),
												'tab2_active'		=>	$this->config->item('active'),
												'tab3'				=>	'',
												'tab4'				=>	'',
												'tab5'				=>	'',
												'tab6'				=>	'',
												'tab7'				=>	'',
												'tab8'				=>	''
											 )			
					 );
		$this->load->vars($data);
		$this->load->theme('default');
    }
    
    function savecall(){
        if($this->session->userdata('user_group')!= $this->config->item('admin') ){
            redirect($this->config->item('call'));
        }
        if($this->input->post('save')){
            //$val=count($this->calls->getCek());
            //if($val<1){
                $this->calls->getSave();
                $this->session->set_flashdata('message','<span class="message success"><strong>Success </strong>message - '.$this->lang->line('m_save').'  </span>');
                redirect($this->input->server('HTTP_REFERER'));
            //}else{
            //    $this->session->set_flashdata('message','<span class="message error"><strong>Success</strong>message - '.$this->lang->line('m_duplicate').'  </span>');
            //    redirect($this->input->server('HTTP_REFERER'));
            //}
        }
    }
    
    function deletecall($id){
        if($this->session->userdata('user_group')!= $this->config->item('admin') ){
            redirect($this->config->item('call'));
        }
        
        if(!$id){
            $this->session->set_flashdata('message','<span class="message error"><strong>Error</strong>message - '.$this->lang->line('m_wrong').'  </span>');    
            redirect($this->config->item('call'));
        }
        
        $this->calls->getRemove($id);
        $this->session->set_flashdata('message','<span class="message success"><strong>Succes </strong>message - '.$this->lang->line('m_delete').'  </span>');
        redirect($this->input->server('HTTP_REFERER'));
        
    }
    
    function editcall($id){
        if($this->session->userdata('user_group')!= $this->config->item('admin') ){
            redirect($this->config->item('call'));
        }
        
        if(!$id){
            $this->session->set_flashdata('message','<span class="message error"><strong>Error</strong>message - '.$this->lang->line('m_wrong').'  </span>');    
            redirect($this->config->item('call'));
        }
           
		$data = array(
						'title'		=>	$this->lang->line('edit').' '.$id,
						'table'		=>	array(
												'users'				=>	$this->calls->getAllUsers(),
                                                'value'				=>	$this->calls->getData($id)
 
											 ),
                        'form'      =>  array('action'=>$this->config->item('call_update')),                     
						'content'	=> 	'form',
						'menu' 		=> 	array(
												'dashboard_active'	=>	$this->config->item('empty'),
												'contact_active'	=>	$this->config->item('empty'),
                                                'contactdna_active'	=>	$this->config->item('empty'),
												'activity_active'	=>	$this->config->item('empty'),
												'job_active'		=>	$this->config->item('empty'),
												'call_active'		=>	$this->config->item('active'),
												'user_active'		=>	$this->config->item('empty'),
												'report_active'		=>	$this->config->item('empty'),
												'master_active'		=>	$this->config->item('empty'),
												'graphic_active'	=>	$this->config->item('empty'),
												'setting_active'	=>	$this->config->item('empty'),
											 ),
						'tab'		=>	array(
												'tab1'				=>	$this->lang->line('list'),
												'tab1_link'			=>	$this->config->item('call'),
												'tab1_active'		=>	$this->config->item('empty'),
												'tab2'				=>	$this->lang->line('add'),
												'tab2_link'			=>	$this->config->item('call_add'),
												'tab2_active'		=>	$this->config->item('empty'),
                                                'tab3'				=>	$this->lang->line('edit'),
                                                'tab3_link'			=>	$this->config->item('call_edit').$id,
												'tab3_active'		=>	$this->config->item('active'),
												'tab4'				=>	'',
												'tab5'				=>	'',
												'tab6'				=>	'',
												'tab7'				=>	'',
												'tab8'				=>	''
											 )			
					 );
		$this->load->vars($data);
		$this->load->theme('default');
    }
    
    function updatecall(){
        if($this->session->userdata('user_group')!= $this->config->item('admin') ){
            redirect($this->config->item('call'));
        }
        if($this->input->post('save')){
            //$val=count($this->users->getCek());
            //if($val){
                $this->calls->getUpdate();
                $this->session->set_flashdata('message','<span class="message success"><strong>Success</strong>message - '.$this->lang->line('m_update').'  </span>');
                redirect($this->input->server('HTTP_REFERER'));
             //}   
        }
    }

}

/* End of file dashboard.php */
/* Location: ./system/application/modules/matchbox/controllers/dashboard.php */